//
//  CollectionVc.m
//  WY_Milk
//
//  Created by wangyang on 2020/2/3.
//  Copyright © 2020 wangyang. All rights reserved.
//

#import "CollectionVc.h"
#import "CollectionVcCell.h"
@interface CollectionVc ()<UITableViewDelegate,UITableViewDataSource,CollectionVcCellDele>

@property (nonatomic,strong) UITableView     *WyHomeTableView;
@property (nonatomic,strong) NSMutableArray     *WyArray;

@end

@implementation CollectionVc

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"我的收藏";
    self.view.backgroundColor = WyWhiteColor;
     [self WyHomeTableView];
}
- (NSMutableArray *)WyArray{
    
    
    if (!_WyArray) {
        _WyArray = [[NSMutableArray alloc] init];
        [_WyArray removeAllObjects];
        
      _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"人物传记"];
        
        
        NSLog(@"%@",_WyArray);
        
        
        
        
    }
    return _WyArray;
    
}
-(UITableView *)WyHomeTableView

{
    
    if (!_WyHomeTableView) {
        
        
        _WyHomeTableView = [[UITableView alloc]init];
           _WyHomeTableView.delegate = self;
           _WyHomeTableView.dataSource = self;
           _WyHomeTableView.showsVerticalScrollIndicator = YES;
           _WyHomeTableView.backgroundColor = [UIColor clearColor];
           _WyHomeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
           _WyHomeTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(Shuaxin)];
           [self.view addSubview:_WyHomeTableView];
           [_WyHomeTableView mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.right.top.bottom.mas_offset(0);
           }];
           [_WyHomeTableView.mj_header beginRefreshing];
           [_WyHomeTableView registerClass:[CollectionVcCell class] forCellReuseIdentifier:@"Cell"];
    }
    return _WyHomeTableView;
    
}
-(void)Shuaxin
{
    [self WyArray];
    [self.WyHomeTableView reloadData];
    [self.WyHomeTableView.mj_header endRefreshing];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
    return self.WyArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellId = @"Cell";
    
    CollectionVcCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
    
    if (!cell) {
        cell = [[CollectionVcCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellId];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    cell.IndexPath = indexPath;

    
    cell.PicImg.image = [UIImage imageNamed:self.WyArray[indexPath.row][@"img"]];
    cell.NameLabe.text = self.WyArray[indexPath.row][@"name"];
    cell.UserNameLabe.text = self.WyArray[indexPath.row][@"UserName"];
    cell.MoneyLabe.text = self.WyArray[indexPath.row][@"money"];
    cell.ScoreLabe.text = self.WyArray[indexPath.row][@"Score"];
    cell.DiscountLabe.text = self.WyArray[indexPath.row][@"Promotion"];
    
    return cell;
}




-(void)WyBtnClickIndexPath:(NSIndexPath *)IndexPath

{
    [MyProgressHUD showWithMaskType:MyProgressHUDMaskTypeBlack];

               //定时器
               dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                  
                 [MyProgressHUD dismiss];
                
                    [self.WyArray removeObjectAtIndex:IndexPath.row];
                    [self.WyHomeTableView reloadData];
                                       
                    [[AlertControllerCustom shareInstance] showAlert:@"取消收藏成功！" viewController:self];
               });
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return BiLiWidth(144);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
